package com.study.model.vo;

import com.github.pagehelper.Page;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;

@Data
@Accessors(chain=true)
public class PageVO<T> {

    @ApiModelProperty("当前页码")
    private int pageNum;

    @ApiModelProperty("每页条数")
    private int pageSize;

    @ApiModelProperty("总页码数")
    private int totalPage;

    @ApiModelProperty("总记录数")
    private long totalSize;

    @ApiModelProperty("分页数据")
    private List<T> data;

    /**
     * Construct 将查询到的实体类List，转为标准分页返回对象
     * @param list 实体对象List
     * @param <K> 实体对象
     * @return 分页对象
     */
    public static <K> PageVO<K> getPageVO(Page<K> page, List<K> list) {
        PageVO<K> pageVO = new PageVO<>();
        pageVO.setPageNum(page.getPageNum())
                .setPageSize(page.getPageSize())
                .setTotalPage(page.getPages())
                .setTotalSize(page.getTotal())
                .setData(list);
        return pageVO;
    }

}

